#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "fileChooser.h"
#include "fileChooser.h"
#include "support.h"

GtkWidget *_fileDialogue;

void
on__fileDialogue_file_activated(GtkFileChooser * filechooser,
				gpointer user_data)
{

	gtk_widget_destroy(_fileDialogue);
}

#include "fileChooser.h"
#include "support.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
  g_object_set_data_full (G_OBJECT (component), name, \
    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)

#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
  g_object_set_data (G_OBJECT (component), name, widget)

GtkWidget *create__fileDialogue(void)
{
	GtkWidget *dialog_vbox2;
	GtkWidget *dialog_action_area2;
	GtkWidget *button1;
	GtkWidget *button2;

	_fileDialogue =
	    gtk_file_chooser_dialog_new("Find File:", NULL,
					GTK_FILE_CHOOSER_ACTION_OPEN, NULL,
					NULL);
	gtk_window_set_type_hint(GTK_WINDOW(_fileDialogue),
				 GDK_WINDOW_TYPE_HINT_DIALOG);

	dialog_vbox2 = GTK_DIALOG(_fileDialogue)->vbox;
	gtk_widget_show(dialog_vbox2);

	dialog_action_area2 = GTK_DIALOG(_fileDialogue)->action_area;
	gtk_widget_show(dialog_action_area2);
	gtk_button_box_set_layout(GTK_BUTTON_BOX(dialog_action_area2),
				  GTK_BUTTONBOX_END);

	button1 = gtk_button_new_from_stock("gtk-cancel");
	gtk_widget_show(button1);
	gtk_dialog_add_action_widget(GTK_DIALOG(_fileDialogue), button1,
				     GTK_RESPONSE_CANCEL);
	GTK_WIDGET_SET_FLAGS(button1, GTK_CAN_DEFAULT);

	button2 = gtk_button_new_from_stock("gtk-open");
	gtk_widget_show(button2);
	gtk_dialog_add_action_widget(GTK_DIALOG(_fileDialogue), button2,
				     GTK_RESPONSE_OK);
	GTK_WIDGET_SET_FLAGS(button2, GTK_CAN_DEFAULT);

	g_signal_connect((gpointer) _fileDialogue, "file_activated",
			 G_CALLBACK(on__fileDialogue_file_activated),
			 NULL);

	/* Store pointers to all widgets, for use by lookup_widget(). */
	GLADE_HOOKUP_OBJECT_NO_REF(_fileDialogue, _fileDialogue,
				   "_fileDialogue");
	GLADE_HOOKUP_OBJECT_NO_REF(_fileDialogue, dialog_vbox2,
				   "dialog_vbox2");
	GLADE_HOOKUP_OBJECT_NO_REF(_fileDialogue, dialog_action_area2,
				   "dialog_action_area2");
	GLADE_HOOKUP_OBJECT(_fileDialogue, button1, "button1");
	GLADE_HOOKUP_OBJECT(_fileDialogue, button2, "button2");

	gtk_widget_grab_default(button2);
	return _fileDialogue;
}
